package cn.zorbus.laian.infrastructure.common.view;

import cn.zorbus.laian.infrastructure.common.command.VideoStatusCommand;
import cn.zorbus.laian.infrastructure.config.FilenameSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Base64;
import java.util.Date;

/**
 * create in 2023/12/3 16:44
 *
 * @author shishaodong
 * @version 0.0.1
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VideoView {

    @JsonView({IDetailView.class})
    String id;

//    @JsonSerialize(using = FilenameSerializer.class)
    @JsonView({ISimpleView.class})
    String filename;

    @JsonView({IDetailView.class})
    String coverPath;

    @JsonIgnore
    byte[] coverImage;

    @JsonView({ISimpleView.class})
    String videoPath;

    @JsonView({IDetailView.class})
    Date lastModified;

    @JsonView({IDetailView.class})
    Integer size;

    @JsonView({ISimpleView.class})
    Integer status;

    public String getVideoPath() {
        return videoPath.replace("\\", "/");
    }

    public void status(@NotNull VideoStatusCommand command) {
        this.status = command.status();
    }


    @Contract(" -> new")
    public static @NotNull VideoView defaultVideoView() {
        return new VideoView();
    }


    public String base64Image() {
        // 将图片字节数组转换为Base64字符串
        String base64Image = Base64.getEncoder().encodeToString(coverImage);
        // 构建Base64数据URL（可选）
        return "data:image/jpeg;base64," + base64Image;
    }
}
